package com.example.myapplication

import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity


//import com.android.build.gradle.api.ApplicationVariant
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        try {
            // 获取当前应用的包名
            val packageName = packageName
            // 获取PackageManager实例
            val packageManager = packageManager
            // 获取ApplicationInfo实例
            val appInfo =
                packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
            // 获取meta-data标签下的值
            val metaData = appInfo.metaData
            val value = metaData.getString("UMENG_CHANNEL")

            // ...
            findViewById<TextView>(R.id.textChannel).text = value
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
    }
}